﻿#region License statement
// NJamb, a specification and delta-specification DSL
// Copyright (c) 2010-2011, Mark Knell
// Published under the MIT License; all other rights reserved
#endregion

#region using...
using NUnit.Framework;
using Rhino.Mocks;
#endregion

namespace NJamb.DemoCode.Antipatterns
{
    [TestFixture]
    public class TemporalDependencyOfMocksInBDD
    {
        private IFoo _foo;
        private FooFacade _testSubject;

        [Test]
        public void ShouldIncrementFooWhenFacadeIsBumped()
        {
            GivenAFoo();
            GivenAFacadeOverFoo();
            WhenBumpFacade();
            ThenIncrementFoo();
        }

        private void GivenAFacadeOverFoo()
        {
            _testSubject = new FooFacade(_foo);
        }

        private void GivenAFoo()
        {
            _foo = MockRepository.GenerateMock<IFoo>();
        }

        private void ThenIncrementFoo()
        {
            _foo.VerifyAllExpectations();
        }

        private void WhenBumpFacade()
        {
            _foo.Expect(x => x.Increment()); // is this right?
            _testSubject.Bump();
        }

        public class FooFacade
        {
            private readonly IFoo _foo;

            public FooFacade(IFoo foo)
            {
                _foo = foo;
            }

            public void Bump()
            {
                _foo.Increment();
            }
        }

        public interface IFoo
        {
            void Increment();
        }
    }
}
